home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Demos / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / DSP (Fourier etc) / CmplxToMagPhase next >
Encoding:
Text File  |  1994-06-03  |  1.5 KB  |  63 lines  |  [TEXT/IGR0]

  1. #include <BringDestToFront>
  2.  
  3. | CmplxToMagPhase converts a complex wave, presumed to be the result of an FFT,
  4. | to _Mag and _Phase waves.
  5. |
  6. Macro CmplxToMagPhase(w,linlog,phase,phasetype)
  7.     string w
  8.     Prompt w,"Complex data wave:",popup WaveList("*",";","")
  9.     variable linlog= 2
  10.     Prompt linlog,"Magnitude mode:",popup "Linear;dB"
  11.     Variable phase= 1
  12.     Prompt phase,"Phase:",popup "No phase;Phase in radians;Phase in degrees"
  13.     Variable phasetype=1
  14.     Prompt phasetype,"Unwrap phase?",popup,"No;Yes"
  15. ;
  16.     PauseUpdate; silent 1
  17.     
  18.     string destw=w+"_Mag",phasew= w+"_Phase"
  19.     Variable n= numpnts($w)
  20.     
  21.     Duplicate/O $w $destw
  22.     $destw= r2polar($destw)    | If error here, $destw is probably not a complex wave
  23.     | NOTE: depending on your application you may want to un-comment the next line
  24. |    $destw[0] /= 2                                | dc is special
  25.     if( phase!=1 )
  26.         Duplicate/O $destw $phasew
  27.         Redimension/R $phasew
  28.         $phasew= imag($destw)
  29.         if( phasetype==2 )
  30.             $phasew[0]= $phasew[1]            | try to avoid glitch at dc
  31.             UnWrap 2*Pi,$phasew
  32.             $phasew[0]= 0
  33.         endif
  34.         if(phase==3)
  35.             $phasew *= 180/Pi
  36.             SetScale y,0,0,"deg",$phasew
  37.         else
  38.             SetScale y,0,0,"rad",$phasew
  39.         endif
  40.     endif
  41.     Redimension/R $destw
  42.     if( linlog==2 )
  43.         WaveStats/Q $destw
  44.         $destw= 20*log($destw/V_max)
  45.         SetScale y,0,0,"dB",$destw
  46.     else
  47.         $destw /= n/2
  48.         SetScale y,0,0,"V",$destw
  49.     endif
  50.     BringDestFront(destw)
  51.     if( phase!=1 )
  52.         CheckDisplayed  $phasew
  53.         if( !V_Flag )
  54.             Append/R $phasew
  55.         endif
  56.     endif
  57.     if( numpnts($destw) <= 129 )
  58.         Modify mode($destw)=4,marker($destw)=19,msize($destw)=1
  59.     else
  60.         Modify mode($destw)=0
  61.     endif
  62. end
  63.